<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionController::Caching::Pages::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionController::Caching::Pages::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/actionpack/lib/action_controller/caching/pages_rb.html">
                vendor/rails/actionpack/lib/action_controller/caching/pages.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000876">cache_page</a>&nbsp;&nbsp;
      <a href="#M000877">caches_page</a>&nbsp;&nbsp;
      <a href="#M000875">expire_page</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000876" class="method-detail">
        <a name="M000876"></a>

        <div class="method-heading">
          <a href="#M000876" class="method-signature">
          <span class="method-name">cache_page</span><span class="method-args">(content, path)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Manually cache the <tt>content</tt> in the key determined by <tt>path</tt>.
Example:
</p>
<pre>
  cache_page &quot;I'm the cached content&quot;, &quot;/lists/show&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000876-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000876-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/caching/pages.rb, line 75</span>
75:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cache_page</span>(<span class="ruby-identifier">content</span>, <span class="ruby-identifier">path</span>)
76:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">perform_caching</span>
77: 
78:           <span class="ruby-identifier">benchmark</span> <span class="ruby-node">&quot;Cached page: #{page_cache_file(path)}&quot;</span> <span class="ruby-keyword kw">do</span>
79:             <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">makedirs</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">page_cache_path</span>(<span class="ruby-identifier">path</span>)))
80:             <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">page_cache_path</span>(<span class="ruby-identifier">path</span>), <span class="ruby-value str">&quot;wb+&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">content</span>) }
81:           <span class="ruby-keyword kw">end</span>
82:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000877" class="method-detail">
        <a name="M000877"></a>

        <div class="method-heading">
          <a href="#M000877" class="method-signature">
          <span class="method-name">caches_page</span><span class="method-args">(*actions)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Caches the <tt>actions</tt> using the page-caching approach that&#8216;ll
store the cache in a path within the page_cache_directory that matches the
triggering url.
</p>
<p>
Usage:
</p>
<pre>
  # cache the index action
  caches_page :index

  # cache the index action except for JSON requests
  caches_page :index, :if =&gt; Proc.new { |c| !c.request.format.json? }
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000877-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000877-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/caching/pages.rb, line 94</span>
94:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">caches_page</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">actions</span>)
95:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">perform_caching</span>
96:           <span class="ruby-identifier">options</span> = <span class="ruby-identifier">actions</span>.<span class="ruby-identifier">extract_options!</span>
97:           <span class="ruby-identifier">after_filter</span>({<span class="ruby-identifier">:only</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">actions</span>}.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)) { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">cache_page</span> }
98:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000875" class="method-detail">
        <a name="M000875"></a>

        <div class="method-heading">
          <a href="#M000875" class="method-signature">
          <span class="method-name">expire_page</span><span class="method-args">(path)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Expires the page that was cached with the <tt>path</tt> as a key. Example:
</p>
<pre>
  expire_page &quot;/lists/show&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000875-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000875-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/caching/pages.rb, line 65</span>
65:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expire_page</span>(<span class="ruby-identifier">path</span>)
66:           <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">perform_caching</span>
67: 
68:           <span class="ruby-identifier">benchmark</span> <span class="ruby-node">&quot;Expired page: #{page_cache_file(path)}&quot;</span> <span class="ruby-keyword kw">do</span>
69:             <span class="ruby-constant">File</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">page_cache_path</span>(<span class="ruby-identifier">path</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">page_cache_path</span>(<span class="ruby-identifier">path</span>))
70:           <span class="ruby-keyword kw">end</span>
71:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>